<?php
/** @noinspection PhpUnused */
declare(strict_types=1);

namespace app\shop\controller;

use app\shop\exception\FailException;
use app\shop\exception\ParamsErrorException;
use app\shop\logic\OrderRefundLogic;
use app\shop\validate\OrderRefundValidate;
use think\response\Json;

/**
 * @property OrderRefundLogic $logic
 */
class OrderRefundController extends BaseController
{
    protected string $validateClassName = OrderRefundValidate::class;

    protected array $noNeedLogin = [];

    public function __construct()
    {
        parent::__construct();

        $this->logic = new OrderRefundLogic();
    }

    /**
     * 售后单列表
     * @return Json
     * @throws ParamsErrorException
     */
    public function list(): Json
    {
        $params = $this->getInput(true);

        $this->validateData($params, 'list');

        $result = $this->logic->list($params);

        return $this->success($result);
    }

    /**
     * 售后单详情
     * @return Json
     * @throws ParamsErrorException|FailException
     */
    public function detail(): Json
    {
        $params = $this->getInput(true);

        $this->validateData($params, 'detail');

        $result = $this->logic->detail($params);

        return $this->success($result);
    }

    /**
     * 售后申请
     * @return Json
     * @throws FailException
     * @throws ParamsErrorException
     */
    public function refund(): Json
    {
        $params = $this->postInput(true);

        $this->validateData($params, 'refund');

        $result = $this->logic->refund($params);

        return $this->success($result);
    }

    /**
     * 用户售后发货
     * @return Json
     * @throws FailException
     * @throws ParamsErrorException
     */
    public function refundReturn(): Json
    {
        $params = $this->postInput(true);

        $this->validateData($params, 'refund_return');

        $result = $this->logic->refundReturn($params);

        return $this->success($result);
    }
}